﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PS_RoyalItemRepays : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        private IRoyalItemRepayBLL reBLL = new RoyalItemRepayBLL();
        private IRoyalItemRepayDetailBLL dtlsBLL = new RoyalItemRepayDetailBLL();

        private RoyalItemRepayInfo reInfo = new RoyalItemRepayInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDataGrid();
            }
        }
        public void LoadDataGrid()
        {
            IList<RoyalItemRepayInfo> Info = reBLL.ListRoyalItems();
            RadGrid1.DataSource = Info;
            RadGrid1.DataBind();
        }
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int RepaySeq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Sequence"]);
                reBLL.Delete(RepaySeq, ssMng.EmpSeqI);                
            }
            LoadDataGrid();
            //if (e.CommandName == "DeleteDtls")
            //{
            //    int Sequence = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemC:\inetpub\wwwroot\GERP_Sourcesafe\KPIS.GERP.GHRMS.APP\App_UI\Forms\DialogRC_EduIns.aspxIndex]["Sequence"]);
            //    dtlsBLL.Delete(Sequence, ssMng.EmpSeqI);
            //}

            //IList<RoyalItemRepayInfo> Info = reBLL.ListRoyalItems();
            //RadGrid1.DataSource = Info;            
        }       

        //protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
        //{
        //    GridDataItem parentItem = (GridDataItem)e.DetailTableView.ParentItem;// .Item.OwnerTableView.ParentItem;
        //    int RepaySeq = Int32.Parse(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["Sequence"].ToString());
        //    Session["ParentSeq"] = RepaySeq.ToString();

        //    RadGrid1.MasterTableView.DetailTables[0].DataSource = dtlsBLL.ListRoyalItemRepayDetails(RepaySeq);

        //    GridGroupByExpression g = new GridGroupByExpression(RadGrid1.MasterTableView.DetailTables[0].Columns[5]);
        //    RadGrid1.MasterTableView.DetailTables[0].GroupByExpressions.Add(g);

        //    RadGrid1.MasterTableView.DetailTables[0].DataBind();
        //} 
   }
}
